package site.service.app;

import site.entity.Category;
import site.entity.Role;
import site.entity.User;
import site.service.repository.CategoryRepository;
import site.service.repository.UserRepository;

public class SiteSystem {

	/**
	 * 初始化网站系统
	 */
	public static void initiate() {
		System.out.println("初始化系统...");

		UserRepository userRepository = new UserRepository();

		// ===== 创建基本角色 ===== //
		Role role = new Role();
		role.setName("系统超级管理员");
		userRepository.saveRole(role);
		role.setName("管理员");
		userRepository.saveRole(role);
		role.setName("用户");
		userRepository.saveRole(role);
		role.setName("企业管理员");
		userRepository.saveRole(role);

		// ===== 创建基本用户 ===== //
		User user = new User();
		user.setName("SiteAdmin");
		user.setEmail("neolimeng@gmail.com");
		user.setPassword("neowoxnsk");
		user.setRoleId(Role.SUPER_ADMINISTRATOR);
		userRepository.saveUser(user);

		// ===== 创建类别基本信息 ===== //
		CategoryRepository categoryRepository = new CategoryRepository();
		Category category = new Category();
		category.setName("最新新闻");
		category.setLevel(Category.LEVEL_TOP);
		category.setType(Category.TYPE_BUILT_IN);
		category.setParentId(1L);
		categoryRepository.saveCategory(category);

		category = new Category();
		category.setName("头条新闻");
		category.setLevel(Category.LEVEL_TOP);
		category.setType(Category.TYPE_BUILT_IN);
		category.setParentId(2L);
		categoryRepository.saveCategory(category);

		category = new Category();
		category.setName("最新通知");
		category.setLevel(Category.LEVEL_TOP);
		category.setType(Category.TYPE_BUILT_IN);
		category.setParentId(3L);
		categoryRepository.saveCategory(category);

		category = new Category();
		category.setName("政策法规");
		category.setLevel(Category.LEVEL_TOP);
		category.setType(Category.TYPE_USER_ADDED);
		category.setParentId(4L);
		categoryRepository.saveCategory(category);

		category = new Category();
		category.setName("技术合作");
		category.setLevel(Category.LEVEL_TOP);
		category.setType(Category.TYPE_USER_ADDED);
		category.setParentId(5L);
		categoryRepository.saveCategory(category);

		category = new Category();
		category.setName("科技攻关");
		category.setLevel(Category.LEVEL_TOP);
		category.setType(Category.TYPE_USER_ADDED);
		category.setParentId(6L);
		categoryRepository.saveCategory(category);

	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		SiteSystem.initiate();
	}

}
